<?php

class LinkageModel extends Model {

    public function get_primary_key() {
        return $this->primary_key = 'id';
    }
	
    public function get_fields() {
        return $this->get_table_fields();
    }

	public function get_all_list($id=0){
		$sql = "select id,name from ".$this->prefix."linkage where parentid=$id and site=1";
		$res = $this->db->query($sql)->result_array();
		return $res;
	}
	public function get_name($id){//根据id获取name
		$sql = "select name from ".$this->prefix."linkage where id=$id";
		$res =  $this->db->query($sql)->row_array();
		return $res['name'];
	}
	
	
	public function get_one_name($id,$p=0){
		$arr = explode(',',$id);
		if(empty($p)){
				$sql = "select name from ".$this->prefix."linkage where id in($id)";
				$res = $this->db->query($sql)->result_array();
				foreach($res as $key=>$v){
					$restr = empty($key)?'':',';
					$data .= $restr.$v['name'];
				}
				return $data;
		}else{
			switch($p){
				case 1:
				$where = "id=".$arr[0]."";
				break;
				case 2:
				$where = "id=".$arr[1]."";
				break;
				case 3:
				$where = "id=".$arr[2]."";
				break;
			}
			$sql = "select name from ".$this->prefix."linkage where $where";
			$res = $this->db->query($sql)->row_array();
			return $res['name'];
		}
	}

	public function get_city_list(){
		$sql=  "select * from ".$this->prefix."linkage where parentid=0 and site=1";
		$res = $this->db->query($sql)->result_array();
		$list = array();
		foreach($res as $v){
			$list[] = $this->get_one_city($v['id']);
		}
		return $list;
	}	
	
	public function get_one_city($id){//读取只开启瑜伽馆筛选的选择
		$sql = "select * from ".$this->prefix."linkage where parentid=$id and if_select=1";
		return $this->db->query($sql)->result_array();
	}
	


}